package com.huqing.icu.controller.app;

import com.huqing.icu.base.BaseController;
import com.huqing.icu.base.IdReq;
import com.huqing.icu.enums.*;
import com.huqing.icu.inout.in.app.*;
import com.huqing.icu.service.app.IAppHouseService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.Arrays;


/**
 * 客户端房源接口
 *
 * @author huqing
 * @date 2024-09-15 23:16:21
 */

@RestController
@RequestMapping("/api/house")
@Tag(name = "客户端房源接口")
public class AppHouseController extends BaseController {

    @Autowired
    private IAppHouseService houseService;

    @Operation(summary = "新增房源")
    @RequestMapping(value = "/add", method = RequestMethod.POST, produces = "application/json")
    public String saveOrUpdate(HttpServletRequest request, @RequestBody HouseAddReq houseAddReq) {
        /*Long userId = checkAndGetUserId(request);
        houseAddReq.setUserId(userId);*/

        houseAddReq = new HouseAddReq();
        houseAddReq.setUserId(9600L);
        houseAddReq.setTitle("一室一厅，风水好，交通方便");
        houseAddReq.setDescription("房子采光非常好，非常通风，我经常在门口乘凉");
        houseAddReq.setHouseCommunityName("万科欧泊");
        houseAddReq.setArea(new BigDecimal("80.04"));
        houseAddReq.setFloor(6);
        houseAddReq.setTotalFloor(8);
        houseAddReq.setBuildYear(1997);
        houseAddReq.setHouseType(HouseTypeEnum.ORDINARY_COMMUNITY.getCode());
        houseAddReq.setDirection(HouseDirectionEnum.EAST.getCode());
        houseAddReq.setIsShareRent(IsOrNotEnum.NOT.getCode());
        houseAddReq.setIsLoft(IsOrNotEnum.NOT.getCode());
        houseAddReq.setRootNum(2);
        houseAddReq.setHallNum(1);
        houseAddReq.setToiletNum(1);
        houseAddReq.setIsLongRental(IsOrNotEnum.IS.getCode());
        houseAddReq.setRentMonthNum(6);
        houseAddReq.setHasElevator(IsOrNotEnum.IS.getCode());
        houseAddReq.setHasBed(IsOrNotEnum.IS.getCode());
        houseAddReq.setHasWardrobe(IsOrNotEnum.IS.getCode());
        houseAddReq.setHasTV(IsOrNotEnum.IS.getCode());
        houseAddReq.setHasAirConditioning(IsOrNotEnum.IS.getCode());
        houseAddReq.setHasFridge(IsOrNotEnum.IS.getCode());
        houseAddReq.setHasWashingMachine(IsOrNotEnum.IS.getCode());
        houseAddReq.setHasNaturalGas(IsOrNotEnum.IS.getCode());
        houseAddReq.setHasWaterHeater(IsOrNotEnum.IS.getCode());
        houseAddReq.setImageList(Arrays.asList("https://img0.baidu.com/it/u=1599449235,3570972399&fm=253&app=138&f=JPEG?w=800&h=1067",
                "https://pics0.baidu.com/feed/b03533fa828ba61eb14574d952b26b05314e5936.jpeg?token=1932ebcd746f5a2cb33f5a35330a9add"));
        houseAddReq.setVideoUrl("https://www.bilibili.com/video/BV1PF4m1V78c?t=3.7");
        houseAddReq.setWaterElectricityType(HouseWaterElectricityTypeEnum.CIVIL_WATER_AND_ELECTRICITY.getCode());
        houseAddReq.setWaterPrice(new BigDecimal("5"));
        houseAddReq.setElectricityPrice(new BigDecimal("0.8"));
        houseAddReq.setPropertyManageFee(new BigDecimal("78"));
        houseAddReq.setAgencyPrice(new BigDecimal("0"));
        houseAddReq.setRentPrice(new BigDecimal("1700"));
        houseAddReq.setDeposit(new BigDecimal("6400"));
        houseAddReq.setHasPark(IsOrNotEnum.IS.getCode());
        houseAddReq.setMonthParkPrice(new BigDecimal("35"));
        houseAddReq.setHouseOwner(HouseOwnerEnum.PROPRIETORS.getCode());
        houseAddReq.setContactStr("13098898679");
        houseAddReq.setIsOpenConcat(IsOrNotEnum.IS.getCode());
        return jsonSuccessForNull(houseService.insertHouse(houseAddReq));
    }

    @Operation(summary = "修改房源")
    @RequestMapping(value = "/update", method = RequestMethod.POST, produces = "application/json")
    public String saveOrUpdate(HttpServletRequest request, @RequestBody HouseUpdateReq houseUpdateReq) {
        Long userId = checkAndGetUserId(request);
        houseUpdateReq.setUserId(userId);
        return jsonSuccessForNull(houseService.updateHouse(houseUpdateReq));
    }

    @Operation(summary = "查询房源列表")
    @RequestMapping(value = "/query_list", method = RequestMethod.POST, produces = "application/json")
    public String queryList(HttpServletRequest request, @RequestBody AppHouseListQueryReq queryReq) {
        //Long userId = getLoginUserId(request);
        Long userId = 9600L;
        return jsonSuccessForNull(houseService.queryList(queryReq, userId));
    }

    @Operation(summary = "查看房源详情")
    @RequestMapping(value = "/query_detail", method = RequestMethod.POST, produces = "application/json")
    public String queryDetail(HttpServletRequest request, @RequestBody IdReq idReq) {
        //Long userId = getLoginUserId(request);
        Long userId = 9600L;
        idReq.setId(1969415679752462337L);
        return jsonSuccessForNull(houseService.queryDetail(userId, idReq.getId()));
    }


    @Operation(summary = "房源已租出去")
    @RequestMapping(value = "/rent_out", method = RequestMethod.POST, produces = "application/json")
    public String rentOut(HttpServletRequest request, @RequestBody RentOutReq rentOutReq) {
        return jsonSuccessForNull(houseService.rentOut(rentOutReq));
    }

    @Operation(summary = "查询用户的房源列表")
    @RequestMapping(value = "/query_user_house", method = RequestMethod.POST, produces = "application/json")
    public String queryUserHouse(@RequestBody UserHouseQueryReq queryReq, HttpServletRequest request) {
        //Long userId = getLoginUserId(request);
        Long loginUserId = 9600L;
        return jsonSuccessForNull(houseService.queryUserHouse(queryReq, loginUserId));
    }
}
